package com.shou.lifecollege.modules.common.service.Impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shou.lifecollege.modules.common.entity.SysRole;
import com.shou.lifecollege.modules.common.mapper.SysRoleMapper;
import com.shou.lifecollege.modules.common.service.SysRoleService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author: luotian
 * @Date: 2022/11/24 12:45
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public List<SysRole> getRoleByUserId(String id) {
        if(!Strings.isEmpty(id))
        {
            return sysRoleMapper.getRoleByUserId(id);
        }
        return null;
    }

    @Override
    public Set<String> getRoleStringByUserId(String id) {
        List<SysRole> roleList=getRoleByUserId(id);
        Set<String> roleStr=new HashSet<>();
        for(SysRole sysRole:roleList)
        {
            if(ObjectUtil.isNotNull(sysRole))
            {
                roleStr.addAll(Arrays.asList(sysRole.getRole().trim().split(",")));
            }
        }
        return roleStr;

    }
}
